package com.xinyin.aiqinhaiback.service.handStrategy;

import com.xinyin.aiqinhaiback.service.HandleStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
public class HandleStrategyFactory {
	public HandleStrategyFactory() {
	}

	//使用Map集合存储策略信息,彻底消除if...else
	private static Map<Integer, HandleStrategy> strategyMap;
	@Autowired
	private HeatHandleStrategy heatHandleStrategy;
	@Autowired
	private ColdHandleStrategy coldHandleStrategy;

	@PostConstruct
	//初始化具体策略,保存到map集合
	public void init(){
		strategyMap = new HashMap<>();
		strategyMap.put(0,heatHandleStrategy);
		strategyMap.put(1,coldHandleStrategy);
	}

	//根据回执类型获取对应策略类对象
	public static HandleStrategy getHandleStrategy(Integer receiptType){
		return strategyMap.get(receiptType);
	}

}
